//
// Mutex.cpp for  in /home/herpec_j/Dropbox/Projets/raytracer-2016/Sources/DesignPattern/ThreadPool/
//
// Made by Jonathan
// Login   <ledey_l@epitech.net>
//
// Started on  Fri Sep 20 13:32:40 2013 Jonathan
// Last update Fri Sep 20 13:46:22 2013 Jonathan
//

#include		<cstdlib>

#include		"DesignPattern/ThreadPool/Mutex.hpp"

namespace		DesignPattern
{
  namespace		ThreadPool
  {
    Mutex::Mutex(void)
    {
      pthread_mutex_init(&mMutex, NULL);
      mIsLocked = false;
    }

    void		Mutex::Lock(void)
    {
      pthread_mutex_lock(&mMutex);
      mIsLocked = true;
    }

    void		Mutex::Unlock(void)
    {
      mIsLocked = false;
      pthread_mutex_unlock(&mMutex);
    }

    pthread_mutex_t	*Mutex::GetMutex(void)
    {
      return (&mMutex);
    }

    Mutex::~Mutex(void)
    {
      if (mIsLocked)
	{
	  Unlock();
	}
      pthread_mutex_destroy(&mMutex);
    }
  };
};
